import axios from 'axios'

const baseURL = 'http://ludir.cn:8888/api/private/v1/'
// const baseURL = 'https://lianghj.top:8888/api/private/v1/'

// 'https://www.liulongbin.top:8888/api/private/v1/'

axios.defaults.baseURL = baseURL
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';

// 设置axios 拦截器
// 取出localStorage中存储的token值
let AUTH_TOKEN = window.localStorage.getItem('myToken') ||''
axios.interceptors.request.use(function (config) {

  if(config.url.includes('1106975712662')){ 
    config.baseURL='https://www.liulongbin.top:8888/api/private/v1/'
    config.headers['Authorization']='Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjUwMCwicmlkIjowLCJpYXQiOjE2Mzg5MjU4MDUsImV4cCI6MTYzOTAxMjIwNX0.R2S3WJp6i1DStWIKuDh8ffpEAbpOlNPt_DvJ-49MHZo'
    
  }else {
    config.baseURL = 'http://ludir.cn:8888/api/private/v1/'
    config.headers['Authorization'] = AUTH_TOKEN     // 设置到请求头中 Authorization这个名字是后台规定的
  }
    

    return config
}, function (error) {
    return Promise.reject(error)
})

// 响应拦截
axios.interceptors.response.use(function (response) {
    // Do something with response data
    // console.log(response);
    return response.data;

  }, function (error) {
    // Do something with response error
    return Promise.reject(error);
  });


// 登录验证
export const checkLogin = (params) => axios.post("login", params)
// 用户管理
// 用户数据列表
export let getUsers= (params) => axios.get('users',{params})

// 用户状态改变
export let getChangeUserState= ({id,type}) => axios.put(`users/${id}/state/${type}`)

// 添加用户
export const getAddUsers = (params) => axios.post("users", params)

// 删除用户
export let getDeleteUser= (params) => axios.delete(`users/${params}`)

// 修改用户
export let getEditUser= (params) => axios.put(`users/${params.id}`,params) 

// 获取角色的列表
export const getRoleList = (params) => axios.get('roles')

// 分配角色
export let getAssignUser= (params) => axios.put(`users/${params.id}/role`,{id: params.id, rid: params.rid}) 

// 根据 角色ID 查询角色
export const getRolesInfo = (params) => axios.get(`roles/${params}`)

// 添加角色
export const getAddRoles = (params) => axios.post("roles", params)

// 修改角色
export let getEditRoles= (params) => axios.put(`roles/${params.roleId}`,{roleName: params.roleName, roleDesc: params.roleDesc}) 

// 删除角色
export let getDeleteRoles = (params) => axios.delete(`roles/${params}`)

// 权限列表  值 list 或 tree , list 列表显示权限, tree 树状显示权限
export let getRightList = (params) => axios.get(`rights/${params.type}`)

//  授权角色
export let getConfirmRoleRight = (roleId,{rids}) => axios.post(`roles/${roleId}/rights`,{rids})

// 删除权限
export let getDeleteRoleRight = (params) => axios.delete(`roles/${params.roleId}/rights/${params.rightId}`)

// 左侧菜单列表
export let getMenusList = (params) => axios.get('menus')


// 商品列表数据
export let getGoods= (params) => axios.get('goods',{params})

// 商品分类数据
export let getCategories = (params) => axios.get('categories', {params: params})

// 根据 id 查询分类
export let getCategoriesById = ({cat_id}) => axios.get(`categories/${cat_id}`)

// 编辑提交分类
export let getCategoriesEdit = ({cat_id,cat_name}) => axios.put(`categories/${cat_id}`,{cat_name})

// 删除分类
export let getCategoriesDelete = ({cat_id}) => axios.delete(`categories/${cat_id}`)

// 添加分类
export let getAddCategories = (params) => axios.post("categories",params)

// 参数列表
export let getParams= ({id,sel}) => axios.get(`categories/${id}/attributes`,{params:{sel:sel}})

// 添加动态参数或者静态属性
export let getAddParams = (params) => axios.post(`categories/${params.id}/attributes`,params)

// 删除参数
export let getDeleteParams = ({id,attrid}) => axios.delete(`categories/${id}/attributes/${attrid}`)

// 根据id 查询参数
export let getSearchParams= (params) => axios.get(`categories/${params.cat_id}/attributes/${params.attr_id}`,{params})

// 编辑参数
export let getEditParams = (params) => axios.put(`categories/${params.cat_id}/attributes/${params.attr_id}`,params)



// 订单列表
export let getOrders= (params) => axios.get('orders',{params})

// 物流信息
export let getPostMan= (params) => axios.get(`kuaidi/${params.id}`)

// 基于时间统计的折线图
export let getReports = (params) => axios.get("reports/type/1")